package com.zmn.oms.dubbo.impl.zmn.master.quotation;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.zmn.master.MasterInfoDRO;
import com.zmn.oms.dubbo.interfaces.zmn.master.quotation.MasterQuotationListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.bo.master.quotation.MasterInfoBO;
import com.zmn.oms.zmn.business.interfaces.master.MasterQuotationBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author sunlife
 * @date:2022/3/16 8:54 下午
 * description:
 */
@Slf4j
@DubboService(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class MasterQuotationListRemoteServiceImpl implements MasterQuotationListRemoteService {

    @Autowired
    private MasterQuotationBService masterQuotationBService;

    @Override
    public ResponseDTO<List<MasterInfoDRO>> listOnlineMasterByOrderIdAndWorkId(Long orderId, Long workId) {
        try {
            List<MasterInfoBO> masterInfoList = masterQuotationBService.listOnlineMasterByOrderIdAndWorkId(orderId, workId);
            return ResponseDTO.success(BeanMapper.mapList(masterInfoList, MasterInfoDRO.class));
        } catch (OmsBaseException e) {
            log.error("获取在线工程师信息失败", e);
            return ResponseDTO.fromErrorCodeTable(e.getCode());
        }catch (Exception e) {
            log.error("获取在线工程师信息失败", e);
            return ResponseDTO.fail("请稍后重试");
        }
    }
}
